// components/dusting/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    dataList: {
      type: String,
      value: '{}',
      observer: 'setDataSource'
    },
    recordState: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    dataSource: [{
        text: '20目以下',
        value: '',
        name: '20'
      },
      {
        text: '20 - 40目',
        value: '',
        name: '40'
      },
      {
        text: '40 - 60目',
        value: '',
        name: '60'
      },
      {
        text: '60 - 80目',
        value: '',
        name: '80'
      },
      {
        text: '80-100目',
        value: '',
        name: '100'
      },
      {
        text: '100目以上',
        value: '',
        name: '100+'
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onClose() {
      this.triggerEvent('onClose')

    },
    onSubmit({
      detail
    }) {
      this.triggerEvent('onSubmit', detail);
    },
    setDataSource() {
      const source = JSON.parse(this.properties.dataList || "[]");
      const arr = this.data.dataSource.map(it => {
        return {
          ...it,
          value: source[it.name]
        }
      })
      this.setData({
        dataSource: arr
      })

    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
})